﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using IceScream.Models;
using IceScream.ViewModels;

namespace IceScream.Controllers
{
    public class ProductController : Controller
    {
        //
        // GET: /Product/

        DataEntities storeDB = new DataEntities();

        public ActionResult Index()
        {
            ViewData["pageURL"] = Request.Url;
            var lstPro = storeDB.Products.Where(s => s.Active == true).Take(6).ToList();
            ProductIndexViewModel viewPro = new ProductIndexViewModel()
            {
                ListProduct = lstPro
            };
            
            return View(viewPro);
        }

        public ActionResult Browse(int id)
        {
            var getCategory = storeDB.Categories.Where(a => a.Id == id).FirstOrDefault();
            var getProducts = storeDB.Products.Where(a => a.IdCat == id).ToList();
            ProductIndexViewModel viewModel = new ProductIndexViewModel()
            {
                Category = getCategory,
                ListProduct = getProducts
            };
            return View(viewModel);
        }

        [ChildActionOnly]
        public ActionResult CatMenu()
        {
            var cats = storeDB.Categories.Where(a => a.Active == true).ToList();
            return PartialView(cats);
        }

        [ChildActionOnly]
        public ActionResult OnlineSupport()
        {
            return PartialView();
        }

         [ChildActionOnly]
        public ActionResult LeftPage()
        {
            return PartialView();
        }
        
    }
}
